package com.ruoyi.robot.aop;

import com.ruoyi.robot.entity.Info;
import com.ruoyi.robot.service.InfoService;
import org.aspectj.lang.annotation.*;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;

/**
 *
 *
 * @author 26352
 */
@Component
@Aspect
public class Statistics {

    @Resource
    private InfoService infoService;

    @Pointcut("execution(* com.ruoyi.robot.service.RobotService.getData(String))")
    public void pointCut() {

    }

    // 记录每天接口调用次数
    @After("pointCut()")
    public synchronized void count() {
        int count = 0;
        // 先从数据库中查找出当天当前调用次数
        Info info = infoService.findCount();
        if (info != null) {
            count = info.getCount();
        }
        count++;
        // 把次数持久化到数据库中
        infoService.addCount(count);
    }


}
